public class test05 {
    public static void main(String[] args) {
        Print print = new Print();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    print.printA();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "A").start();

        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    print.printB();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "B").start();
    }
}

class Print {
    private int num1 = 1;
    private int num2 = 65;
    private boolean flag = false;

    public synchronized void printA() throws InterruptedException {
        while (flag) {
            this.wait();
        }
        System.out.print(num1);
        num1++;
        flag = true;
        this.notifyAll();
    }

    public synchronized void printB() throws InterruptedException {
        while (!flag) {
            this.wait();
        }
        System.out.print((char) num2);
        num2++;
        flag = false;
        this.notifyAll();
    }
}
